﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EMANIFEST.Dtos;

namespace TestSaveRecord
{
    /// <summary>
    /// Summary description for TestHouseBillRecord
    /// </summary>
    [TestClass]
    public class TestHouseBillRecord
    {
        public TestHouseBillRecord()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        bool kt;
        eManifestService.EmanifestServiceClient client = new eManifestService.EmanifestServiceClient();

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestHouseBill()
        {
            try
            {
                HouseBillDto hose = new HouseBillDto();
                PortDto port = new PortDto();
                port.PortId = new Guid("0c6679ed-25e3-4178-b865-d9026bd244b1");
                hose.PortIdOfDestination = Guid.NewGuid();
                hose.PortIdOfTranship = Guid.NewGuid();
                hose.PortIdOfLoad = Guid.NewGuid();
                hose.PortIdOfUnload = Guid.NewGuid();


                hose.HouseBillId = new Guid("BAF03C2A-2E60-4C97-908A-FBEC5300F967");
                hose.DocumentId = new Guid("DAB27624-2270-4C40-A977-8856C4A8388A");
                hose.Consignee = "Thuyen Vien update";
                hose.Consigner = "Thuyen Vien";
                hose.PortOfTranship = port;
                hose.PortOfDestination = port;
                hose.PortOfLoad = port;
                hose.PortOfUnload = port;
                hose.BillNumber = "Bill001";
                hose.DateOfBill = DateTime.Now;
                hose.DepartureDate = DateTime.Now;
                hose.CreatedDate = DateTime.Now;
                hose.CreaterId = new Guid("9DF40D0D-7AE6-4048-BD45-6608F93CE46F");
                hose.ItemStatus = 0;
                hose.IsTemp = true;
                hose.MasterBillNo = "";
                hose.DateOfMasterBill = DateTime.Now;
                hose.NumberOfPackage = 100;
                hose.KindOfPackages = "";
                hose.PortNameOfTranship = "";
                hose.PortOfDestination = port;
                hose.PortOfLoad = port;
                hose.PortNameOfUnload = "";



               
                client.SaveHouseBillRecord(hose);

                HouseBillDto hdto = client.GetHouseBillById(hose.HouseBillId);
                if (hdto != null)
                    Console.WriteLine("Cap nhat thanh cong");
                else
                    Console.WriteLine("Cap nhat that bai");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }

        [TestMethod]
        public void DeleteHouseBill()
        {
            try
            {
                ResponseDto res= client.DeleteHouseBill(new Guid("BAF03C2A-2E60-4C97-908A-FBEC5300F967"));
                Console.WriteLine(res.IsSuccess);
                HouseBillDto hdto = client.GetHouseBillById(new Guid("BAF03C2A-2E60-4C97-908A-FBEC5300F967"));
                if (hdto == null)
                    Console.WriteLine("Delete thanh cong");
                else
                    Console.WriteLine("Delete that bai");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }


         [TestMethod]
        public void TestHouseBillItem()
        {
            try
            {
                HouseBillItemDto hbItemdto = new HouseBillItemDto();
                hbItemdto.HouseBillItemId = Guid.NewGuid();// new Guid("BAF03C2A-2E60-4C97-908A-FBEC5300F967");
                hbItemdto.HouseBillId = new Guid("BAF03C2A-2E60-4C97-908A-FBEC5300F967");
                hbItemdto.GrossWeight = 100;
                hbItemdto.Demension = 100;
                hbItemdto.ContNumber = "Number 01";
                hbItemdto.ContSealNumber = "Seal Number 05";

                client.SaveHouseBillItemRecord(hbItemdto);

                HouseBillDto hbdto = client.GetHouseBillById(new Guid("DC20C1E3-BA22-436D-9804-62F8AEB9BA6A"));
                
                //List<HouseBillItemDto> lst = hbdto.HouseBillItems;
                //foreach (var item in lst)
                //{
                //    if (item.HouseBillItemId == hbItemdto.HouseBillItemId)
                //    {
                //        Console.WriteLine("Cap nhat thanh cong");
                //        kt = true;
                //        break;
                //    }
                //    else
                //    {
                //        kt = false;
                //    }
                //}
                //if(!kt)
                //    Console.WriteLine("Cap nhat that bai");

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }

        }

         [TestMethod]
         public void DeleteHouseBillItem()
         {
             try
             {
                 ResponseDto res = client.DeleteHouseBillItem(new Guid("BAF03C2A-2E60-4C97-908A-FBEC5300F967"));
                Console.WriteLine(res.IsSuccess);
             }
             catch(Exception ex)
             {
                 Console.WriteLine(ex.InnerException.Message);
             }
         }
    }
}
